package com.qlslylq.ad.sdk.core.mgr;

import com.qlslylq.ad.sdk.application.AdMergeSDKApp;
import com.qlslylq.ad.sdk.constant.AppConst;
import com.qlslylq.ad.sdk.enums.AdType;
import com.qlslylq.ad.sdk.util.Log;
import com.qlslylq.ad.sdk.util.SPUtils;

/**
 * created by qlslylq <br/>
 * on 2022/2/11 <br/>
 * 策略游标管理类<br/>
 */
public class PolicyCursorMgr {

    private static PolicyCursorMgr instance;

    private PolicyCursorMgr() {

    }

    public static PolicyCursorMgr getInstance() {
        if (instance == null) {
            instance = new PolicyCursorMgr();
        }
        return instance;
    }

    /**
     * 获取当前游标<br/>
     */
    public int getCursor(String cursorKey) {
        return (int) SPUtils.get(AdMergeSDKApp.getInstance(), cursorKey, AppConst.IDLE);
    }

    /**
     * 设置当前游标<br/>
     */
    public void setCursor(String cursorKey, int cursor) {
        SPUtils.put(AdMergeSDKApp.getInstance(), cursorKey, cursor);
    }

    /**
     * 重置游标<br/>
     */
    public void resetCursor(String cursorKey) {
        SPUtils.put(AdMergeSDKApp.getInstance(), cursorKey, AppConst.IDLE);
    }

    /**
     * 重置所有策略<br/>
     */
    public void resetAllCursor() {
        String[] keys = new String[]{SPUtils.KEY_SPLASH_CURSOR, SPUtils.KEY_INTERSTITIAL_CURSOR, SPUtils.KEY_REWARD_CURSOR, SPUtils.KEY_FULL_SCREEN_CURSOR, SPUtils.KEY_BANNER_CURSOR, SPUtils.KEY_FEED_CURSOR};
        for (String item : keys) {
            SPUtils.put(AdMergeSDKApp.getInstance(), item, AppConst.IDLE);
        }
    }

    /**
     * 打印当前游标<br/>
     */
    public void output(AdType adType, String cursorKey) {
        if (AppConst.openSecretLog) {
            Log.dp(String.format("当前策略游标值[%s]：cursor = %s", adType.getId(), getCursor(cursorKey)));
        }
    }
}
